1 module directx.d3dcompiler; 2 ////////////////////////////////////////////////////////////////////////////// 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // File: D3DCompiler.h 7 // Content: D3D Compilation Types and APIs 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 version(Windows): 12 13 version(Direct3D_9) 14 version = Direct3D; 15 version(Direct3D_10) 16 version = Direct3D; 17 version(Direct3D_11) 18 version = Direct3D; 19 version(Direct3D_12) 20 version = Direct3D; 21 22 version(Direct3D): 23 24 public import directx.d3d11shader; 25 public import directx.d3d12shader; 26 27 28 // useful enums for shader versions 29 alias LPCSTR_D3D_SHADER_TARGET_ext = LPCSTR; 30 enum : LPCSTR_D3D_SHADER_TARGET_ext 31 { 32 // Direct3D 11.0 and 11.1 33 34 cs_5_0 = "cs_5_0", 35 ds_5_0 = "ds_5_0", 36 gs_5_0 = "gs_5_0", 37 hs_5_0 = "hs_5_0", 38 ps_5_0 = "ps_5_0", 39 vs_5_0 = "vs_5_0", 40 41 // Direct3D 10.1 42 43 cs_4_1 = "cs_4_1", 44 gs_4_1 = "gs_4_1", 45 ps_4_1 = "ps_4_1", 46 vs_4_1 = "vs_4_1", 47 48 // Direct3D 10.0 49 50 cs_4_0 = "cs_4_0", 51 gs_4_0 = "gs_4_0", 52 ps_4_0 = "ps_4_0", 53 vs_4_0 = "vs_4_0", 54 55 // Direct3D 9.1, 9.2, 9.3 56 57 ps_4_0_level_9_1 = "ps_4_0_level_9_1", 58 ps_4_0_level_9_3 = "ps_4_0_level_9_3", 59 vs_4_0_level_9_1 = "vs_4_0_level_9_1", 60 vs_4_0_level_9_3 = "vs_4_0_level_9_3", 61 62 // Legacy Direct3D 9 SM 3.0 63 64 ps_3_0 = "ps_3_0", 65 ps_3_sw = "ps_3_sw", 66 vs_3_0 = "vs_3_0", 67 vs_3_sw = "vs_3_sw", 68 69 // Legacy Direct3D 9 SM 2.0 70 71 ps_2_0 = "ps_2_0", 72 ps_2_a = "ps_2_a", 73 ps_2_b = "ps_2_b", 74 ps_2_sw = "ps_2_sw", 75 vs_2_0 = "vs_2_0", 76 vs_2_a = "vs_2_a", 77 vs_2_sw = "vs_2_sw", 78 79 // Legacy effects 80 81 fx_2_0 = "fx_2_0", 82 fx_4_0 = "fx_4_0", 83 fx_4_1 = "fx_4_1", 84 fx_5_0 = "fx_5_0", 85 86 } // enum LPCSTR_D3D_SHADER_TARGET_ext 87 88 89 ////////////////////////////////////////////////////////////////////////////// 90 // APIs ////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////// 92 93 94 /// predefined for D3DDisassemble10Effect 95 interface ID3D10Effect : IUnknown {} 96 97 extern(C) 98 { 99 100 //---------------------------------------------------------------------------- 101 // D3DCOMPILE flags: 102 // ----------------- 103 // D3DCOMPILE_DEBUG 104 // Insert debug file/line/type/symbol information. 105 // 106 // D3DCOMPILE_SKIP_VALIDATION 107 // Do not validate the generated code against known capabilities and 108 // constraints. This option is only recommended when compiling shaders 109 // you KNOW will work. (ie. have compiled before without this option.) 110 // Shaders are always validated by D3D before they are set to the device. 111 // 112 // D3DCOMPILE_SKIP_OPTIMIZATION 113 // Instructs the compiler to skip optimization steps during code generation. 114 // Unless you are trying to isolate a problem in your code using this option 115 // is not recommended. 116 // 117 // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 118 // Unless explicitly specified, matrices will be packed in row-major order 119 // on input and output from the shader. 120 // 121 // D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 122 // Unless explicitly specified, matrices will be packed in column-major 123 // order on input and output from the shader. This is generally more 124 // efficient, since it allows vector-matrix multiplication to be performed 125 // using a series of dot-products. 126 // 127 // D3DCOMPILE_PARTIAL_PRECISION 128 // Force all computations in resulting shader to occur at partial precision. 129 // This may result in faster evaluation of shaders on some hardware. 130 // 131 // D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 132 // Force compiler to compile against the next highest available software 133 // target for vertex shaders. This flag also turns optimizations off, 134 // and debugging on. 135 // 136 // D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 137 // Force compiler to compile against the next highest available software 138 // target for pixel shaders. This flag also turns optimizations off, 139 // and debugging on. 140 // 141 // D3DCOMPILE_NO_PRESHADER 142 // Disables Preshaders. Using this flag will cause the compiler to not 143 // pull out static expression for evaluation on the host cpu 144 // 145 // D3DCOMPILE_AVOID_FLOW_CONTROL 146 // Hint compiler to avoid flow-control constructs where possible. 147 // 148 // D3DCOMPILE_PREFER_FLOW_CONTROL 149 // Hint compiler to prefer flow-control constructs where possible. 150 // 151 // D3DCOMPILE_ENABLE_STRICTNESS 152 // By default, the HLSL/Effect compilers are not strict on deprecated syntax. 153 // Specifying this flag enables the strict mode. Deprecated syntax may be 154 // removed in a future release, and enabling syntax is a good way to make 155 // sure your shaders comply to the latest spec. 156 // 157 // D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 158 // This enables older shaders to compile to 4_0 targets. 159 // 160 //---------------------------------------------------------------------------- 161 162 enum D3DCOMPILE_DEBUG = (1 << 0); 163 enum D3DCOMPILE_SKIP_VALIDATION = (1 << 1); 164 enum D3DCOMPILE_SKIP_OPTIMIZATION = (1 << 2); 165 enum D3DCOMPILE_PACK_MATRIX_ROW_MAJOR = (1 << 3); 166 enum D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR = (1 << 4); 167 enum D3DCOMPILE_PARTIAL_PRECISION = (1 << 5); 168 enum D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT = (1 << 6); 169 enum D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT = (1 << 7); 170 enum D3DCOMPILE_NO_PRESHADER = (1 << 8); 171 enum D3DCOMPILE_AVOID_FLOW_CONTROL = (1 << 9); 172 enum D3DCOMPILE_PREFER_FLOW_CONTROL = (1 << 10); 173 enum D3DCOMPILE_ENABLE_STRICTNESS = (1 << 11); 174 enum D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY = (1 << 12); 175 enum D3DCOMPILE_IEEE_STRICTNESS = (1 << 13); 176 enum D3DCOMPILE_OPTIMIZATION_LEVEL0 = (1 << 14); 177 enum D3DCOMPILE_OPTIMIZATION_LEVEL1 = 0; 178 enum D3DCOMPILE_OPTIMIZATION_LEVEL2 = ((1 << 14) | (1 << 15)); 179 enum D3DCOMPILE_OPTIMIZATION_LEVEL3 = (1 << 15); 180 enum D3DCOMPILE_RESERVED16 = (1 << 16); 181 enum D3DCOMPILE_RESERVED17 = (1 << 17); 182 enum D3DCOMPILE_WARNINGS_ARE_ERRORS = (1 << 18); 183 184 //---------------------------------------------------------------------------- 185 // D3DCOMPILE_EFFECT flags: 186 // ------------------------------------- 187 // These flags are passed in when creating an effect, and affect 188 // either compilation behavior or runtime effect behavior 189 // 190 // D3DCOMPILE_EFFECT_CHILD_EFFECT 191 // Compile this .fx file to a child effect. Child effects have no 192 // initializers for any shared values as these are initialied in the 193 // master effect (pool). 194 // 195 // D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS 196 // By default, performance mode is enabled. Performance mode 197 // disallows mutable state objects by preventing non-literal 198 // expressions from appearing in state object definitions. 199 // Specifying this flag will disable the mode and allow for mutable 200 // state objects. 201 // 202 //---------------------------------------------------------------------------- 203 204 enum D3DCOMPILE_EFFECT_CHILD_EFFECT = (1 << 0); 205 enum D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS = (1 << 1); 206 207 //---------------------------------------------------------------------------- 208 // D3DCompile: 209 // ---------- 210 // Compile source text into bytecode appropriate for the given target. 211 //---------------------------------------------------------------------------- 212 extern(Windows) nothrow 213 HRESULT D3DCompile( 214 LPCVOID pSrcData, 215 SIZE_T SrcDataSize, 216 LPCSTR pSourceName, 217 const(D3D_SHADER_MACRO)* pDefines, 218 ID3DInclude pInclude, 219 LPCSTR pEntrypoint, 220 LPCSTR pTarget, 221 UINT Flags1, 222 UINT Flags2, 223 ID3DBlob* ppCode, 224 ID3DBlob* ppErrorMsgs); 225 226 alias pD3DCompile = extern(Windows) nothrow HRESULT function( 227 LPCVOID pSrcData, 228 SIZE_T SrcDataSize, 229 LPCSTR pFileName, 230 const(D3D_SHADER_MACRO)* pDefines, 231 ID3DInclude pInclude, 232 LPCSTR pEntrypoint, 233 LPCSTR_D3D_SHADER_TARGET_ext pTarget, 234 UINT Flags1, 235 UINT Flags2, 236 ID3DBlob* ppCode, 237 ID3DBlob* ppErrorMsgs); 238 239 240 // NOTE: Since D3DCompiler_44 D3DCompileFromFile is now part of the DirectX rather than Windows 241 extern(Windows) nothrow 242 HRESULT D3DCompileFromFile( 243 LPCWSTR pFileName, 244 const(D3D_SHADER_MACRO)* pDefines, 245 ID3DInclude pInclude, 246 LPCSTR pEntrypoint, 247 LPCSTR pTarget, 248 UINT Flags1, 249 UINT Flags2, 250 ID3DBlob* ppCode, 251 ID3DBlob* ppErrorMsgs); 252 253 //---------------------------------------------------------------------------- 254 // D3DPreprocess: 255 // ---------- 256 // Process source text with the compiler's preprocessor and return 257 // the resulting text. 258 //---------------------------------------------------------------------------- 259 260 extern(Windows) nothrow 261 HRESULT D3DPreprocess( 262 LPCVOID pSrcData, 263 SIZE_T SrcDataSize, 264 LPCSTR pSourceName, 265 const(D3D_SHADER_MACRO)* pDefines, 266 ID3DInclude pInclude, 267 ID3DBlob* ppCodeText, 268 ID3DBlob* ppErrorMsgs); 269 270 alias pD3DPreprocess = extern(Windows) nothrow HRESULT function( 271 LPCVOID pSrcData, 272 SIZE_T SrcDataSize, 273 LPCSTR pFileName, 274 const(D3D_SHADER_MACRO)* pDefines, 275 ID3DInclude pInclude, 276 ID3DBlob* ppCodeText, 277 ID3DBlob* ppErrorMsgs); 278 279 //---------------------------------------------------------------------------- 280 // D3DGetDebugInfo: 281 // ----------------------- 282 // Gets shader debug info. Debug info is generated by D3DCompile and is 283 // embedded in the body of the shader. 284 //---------------------------------------------------------------------------- 285 286 extern(Windows) nothrow 287 HRESULT D3DGetDebugInfo( 288 LPCVOID pSrcData, 289 SIZE_T SrcDataSize, 290 ID3DBlob* ppDebugInfo); 291 292 //---------------------------------------------------------------------------- 293 // D3DReflect: 294 // ---------- 295 // Shader code contains metadata that can be inspected via the 296 // reflection APIs. 297 //---------------------------------------------------------------------------- 298 299 extern(Windows) nothrow 300 HRESULT D3DReflect( 301 LPCVOID pSrcData, 302 SIZE_T SrcDataSize, 303 REFIID pInterface, 304 void** ppReflector); 305 306 //---------------------------------------------------------------------------- 307 // D3DDisassemble: 308 // ---------------------- 309 // Takes a binary shader and returns a buffer containing text assembly. 310 //---------------------------------------------------------------------------- 311 312 enum D3D_DISASM_ENABLE_COLOR_CODE = 0x00000001; 313 enum D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS = 0x00000002; 314 enum D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING = 0x00000004; 315 enum D3D_DISASM_ENABLE_INSTRUCTION_CYCLE = 0x00000008; 316 enum D3D_DISASM_DISABLE_DEBUG_INFO = 0x00000010; 317 318 extern(Windows) nothrow 319 HRESULT D3DDisassemble( 320 LPCVOID pSrcData, 321 SIZE_T SrcDataSize, 322 UINT Flags, 323 LPCSTR szComments, 324 ID3DBlob* ppDisassembly); 325 326 alias pD3DDisassemble = extern(Windows) nothrow HRESULT function( 327 LPCVOID pSrcData, 328 SIZE_T SrcDataSize, 329 UINT Flags, 330 LPCSTR szComments, 331 ID3DBlob* ppDisassembly); 332 333 //---------------------------------------------------------------------------- 334 // D3DDisassemble10Effect: 335 // ----------------------- 336 // Takes a D3D10 effect interface and returns a 337 // buffer containing text assembly. 338 //---------------------------------------------------------------------------- 339 340 extern(Windows) nothrow 341 HRESULT D3DDisassemble10Effect( 342 ID3D10Effect pEffect, 343 UINT Flags, 344 ID3DBlob* ppDisassembly); 345 346 //---------------------------------------------------------------------------- 347 // D3DGetInputSignatureBlob: 348 // ----------------------- 349 // Retrieve the input signature from a compilation result. 350 //---------------------------------------------------------------------------- 351 352 extern(Windows) nothrow 353 HRESULT D3DGetInputSignatureBlob( 354 LPCVOID pSrcData, 355 SIZE_T SrcDataSize, 356 ID3DBlob* ppSignatureBlob); 357 358 //---------------------------------------------------------------------------- 359 // D3DGetOutputSignatureBlob: 360 // ----------------------- 361 // Retrieve the output signature from a compilation result. 362 //---------------------------------------------------------------------------- 363 364 extern(Windows) nothrow 365 HRESULT D3DGetOutputSignatureBlob( 366 LPCVOID pSrcData, 367 SIZE_T SrcDataSize, 368 ID3DBlob* ppSignatureBlob); 369 370 //---------------------------------------------------------------------------- 371 // D3DGetInputAndOutputSignatureBlob: 372 // ----------------------- 373 // Retrieve the input and output signatures from a compilation result. 374 //---------------------------------------------------------------------------- 375 376 extern(Windows) nothrow 377 HRESULT D3DGetInputAndOutputSignatureBlob( 378 LPCVOID pSrcData, 379 SIZE_T SrcDataSize, 380 ID3DBlob* ppSignatureBlob); 381 382 //---------------------------------------------------------------------------- 383 // D3DStripShader: 384 // ----------------------- 385 // Removes unwanted blobs from a compilation result 386 //---------------------------------------------------------------------------- 387 388 enum D3DCOMPILER_STRIP_FLAGS 389 { 390 D3DCOMPILER_STRIP_REFLECTION_DATA = 1, 391 D3DCOMPILER_STRIP_DEBUG_INFO = 2, 392 D3DCOMPILER_STRIP_TEST_BLOBS = 4, 393 D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff, 394 } 395 396 extern(Windows) nothrow 397 HRESULT D3DStripShader( 398 LPCVOID pShaderBytecode, 399 SIZE_T BytecodeLength, 400 UINT uStripFlags, 401 ID3DBlob* ppStrippedBlob); 402 403 //---------------------------------------------------------------------------- 404 // D3DGetBlobPart: 405 // ----------------------- 406 // Extracts information from a compilation result. 407 //---------------------------------------------------------------------------- 408 alias D3D_BLOB_PART = int; 409 enum : D3D_BLOB_PART 410 { 411 D3D_BLOB_INPUT_SIGNATURE_BLOB, 412 D3D_BLOB_OUTPUT_SIGNATURE_BLOB, 413 D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB, 414 D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB, 415 D3D_BLOB_ALL_SIGNATURE_BLOB, 416 D3D_BLOB_DEBUG_INFO, 417 D3D_BLOB_LEGACY_SHADER, 418 D3D_BLOB_XNA_PREPASS_SHADER, 419 D3D_BLOB_XNA_SHADER, 420 421 // Test parts are only produced by special compiler versions and so 422 // are usually not present in shaders. 423 D3D_BLOB_TEST_ALTERNATE_SHADER = 0x8000, 424 D3D_BLOB_TEST_COMPILE_DETAILS, 425 D3D_BLOB_TEST_COMPILE_PERF, 426 } 427 428 extern(Windows) nothrow 429 HRESULT D3DGetBlobPart( 430 LPCVOID pSrcData, 431 SIZE_T SrcDataSize, 432 D3D_BLOB_PART Part, 433 UINT Flags, 434 ID3DBlob* ppPart); 435 436 //---------------------------------------------------------------------------- 437 // D3DCompressShaders: 438 // ----------------------- 439 // Compresses a set of shaders into a more compact form. 440 //---------------------------------------------------------------------------- 441 442 struct _D3D_SHADER_DATA 443 { 444 LPCVOID pBytecode; 445 SIZE_T BytecodeLength; 446 } 447 alias _D3D_SHADER_DATA D3D_SHADER_DATA; 448 449 enum D3D_COMPRESS_SHADER_KEEP_ALL_PARTS = 0x00000001; 450 451 extern(Windows) nothrow 452 HRESULT D3DCompressShaders( 453 UINT uNumShaders, 454 D3D_SHADER_DATA* pShaderData, 455 UINT uFlags, 456 ID3DBlob* ppCompressedData); 457 458 //---------------------------------------------------------------------------- 459 // D3DDecompressShaders: 460 // ----------------------- 461 // Decompresses one or more shaders from a compressed set. 462 //---------------------------------------------------------------------------- 463 464 extern(Windows) nothrow 465 HRESULT D3DDecompressShaders( 466 LPCVOID pSrcData, 467 SIZE_T SrcDataSize, 468 UINT uNumShaders, 469 UINT uStartIndex, 470 UINT* pIndices, 471 UINT uFlags, 472 ID3DBlob* ppShaders, 473 UINT* pTotalShaders); 474 475 //---------------------------------------------------------------------------- 476 // D3DCreateBlob: 477 // ----------------------- 478 // Create an ID3DBlob instance. 479 //---------------------------------------------------------------------------- 480 481 extern(Windows) nothrow 482 HRESULT D3DCreateBlob( 483 SIZE_T Size, 484 ID3DBlob* ppBlob); 485 486 487 }